<?php
/**
 * 开放平台基础类文件 授权及消息通知的实现
 */
namespace app\common\helper\upload;
use think\Exception;
class UploadLocalHandler{
    private $config;
    private $url;
    public function __construct($config) {
        $this->config = $config;
        $this->url = rtrim($config['domain'],'\/');
    }
    
    public function upload($file,$name){
        $dir = root_path().'/public/upload/';
        $fullname = $dir.$name;
        if(file_exists($fullname)){
            throw new Exception('文件已经存在');
        }
        move_uploaded_file($file['tmp_name'], $fullname);
        return [
            'url'   => $this->url . '/'.$name,
            'key'   => $name,
            'hash'  => md5($name), //其实应该md5 file的
        ];
    }
    
    public function delete(){
        
    }
    
}